package com.samapp.indent;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.samapp.R;
import com.samapp.entity.DetectionItem;

public class DetectionItemListAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<DetectionItem> listDetectionItem;

	public DetectionItemListAdapter(Context context, List<DetectionItem> listDetectionItem) {
		this.mInflater = LayoutInflater.from(context);
		this.listDetectionItem = listDetectionItem;
	}

	@Override
	public int getCount() {
		return listDetectionItem.size();
	}

	@Override
	public Object getItem(int position) {
		return listDetectionItem.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.detection_item, parent, false);
			holder = new ViewHolder();
			holder.number = (TextView) convertView.findViewById(R.id.textview_number);
			holder.department = (TextView) convertView.findViewById(R.id.textview_department);
			holder.cnname = (TextView) convertView.findViewById(R.id.textview_cnname);
			holder.type = (TextView) convertView.findViewById(R.id.textview_type);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		DetectionItem mDetectionItem = listDetectionItem.get(position);
		holder.number.setText("项目编号：" + mDetectionItem.getNumber());
		holder.department.setText("部门：" + mDetectionItem.getDepartment());
		holder.cnname.setText("项目名称(中)：" + mDetectionItem.getCnname());
		holder.type.setText("类别：" + mDetectionItem.getType());
		return convertView;
	}

	private class ViewHolder {
		TextView number;
		TextView department;
		TextView cnname;
		TextView type;
	}

}
